package com.mynotes.notes.adapter;

import java.util.List;

import com.mynotes.notes.R;
import com.mynotes.notes.entity.Note;
import com.mynotes.notes.utils.SortName;
import com.mynotes.notes.utils.imageLoader;
import com.mynotes.notes.view.RoundImage;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class GroupNotesAdapter extends BaseAdapter {
	private Context context;
	private List<Note> notes;
	private LayoutInflater inflater;
	private ViewHolder holder;
	private ImageLoader loader;

	public GroupNotesAdapter(Context context, List<Note> notes) {
		inflater = LayoutInflater.from(context);
		this.context = context;
		this.notes = notes;
		loader = imageLoader.getLoader(context);
	}

	@Override
	public int getCount() {
		// Auto-generated method stub
		return notes.size();
	}

	@Override
	public Object getItem(int arg0) {
		// Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View view, ViewGroup arg2) {
		View v;
		holder = new ViewHolder();
		if (view == null) {
			v = inflater.inflate(R.layout.group_notes_item, null);
		} else {
			v = view;
		}
		holder.head = (RoundImage) v.findViewById(R.id.group_notes_head);
		holder.to = (ImageView) v.findViewById(R.id.group_notes_to);
		holder.title = (TextView) v.findViewById(R.id.group_notes_title);
		holder.msg = (TextView) v.findViewById(R.id.group_notes_msg);
		holder.time = (TextView) v.findViewById(R.id.group_notes_time);

		String uri = "http://hua.unohacha.com/upload/"
				+ notes.get(arg0).getFromIcon();
		loader.displayImage(uri, holder.head, imageLoader.options);
		// holder.head.setImageResource(SortName.img1);
		holder.title.setText(notes.get(arg0).getNoteTitle());
		holder.msg.setText(notes.get(arg0).getNoteBody());
		holder.time.setText(notes.get(arg0).getNoteTime());
		return v;
	}

	private class ViewHolder {
		private RoundImage head;
		private ImageView to;
		private TextView title;
		private TextView msg;
		private TextView time;
	}

}